package cuongnh.project.japanesediary.vocabulary.ui.editor.vocabulary.page.grammar;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.FormPage;
import org.eclipse.ui.forms.widgets.Section;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cuongnh.project.japanesediary.vocabulary.common.CommonServices;
import cuongnh.project.japanesediary.vocabulary.model.Vocabulary;
import cuongnh.project.japanesediary.vocabulary.ui.editor.vocabulary.page.grammar.section.VocabularyGrammarsSection;

public class VocabularyGrammarsPage extends FormPage {

	private static Logger m_Log = LoggerFactory
			.getLogger(VocabularyGrammarsPage.class);

	private Vocabulary vocabulary;

	private CommonServices commonServices;

	/**
	 * Create the form page.
	 * 
	 * @param editor
	 * @param id
	 * @param title
	 * @wbp.parser.constructor
	 * @wbp.eval.method.parameter id "Some id"
	 * @wbp.eval.method.parameter title "Some title"
	 */
	public VocabularyGrammarsPage(FormEditor editor, String id, String title,
			Vocabulary vocabulary, CommonServices commonServices) {
		super(editor, id, title);
		this.vocabulary = vocabulary;
		this.commonServices = commonServices;
	}

	/**
	 * Create contents of the form.
	 * 
	 * @param managedForm
	 */
	@Override
	protected void createFormContent(IManagedForm managedForm) {
		managedForm.getForm().getBody().setLayout(new GridLayout(1, false));
		VocabularyGrammarsSection vocabularyGrammarsSection = new VocabularyGrammarsSection(
				managedForm.getForm().getBody(), managedForm.getToolkit(),
				Section.EXPANDED | Section.TITLE_BAR, vocabulary,
				commonServices);
		vocabularyGrammarsSection.getSection().setLayoutData(
				new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		managedForm.addPart(vocabularyGrammarsSection);
	}

	@Override
	public void doSave(IProgressMonitor monitor) {
		m_Log.debug("Saving from VocabularyGrammarsPage!");
		super.doSave(monitor);
	}

}
